package view.game
{
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import global.Define;
	import global.Resource;
	
	import util.EffectCharAdd;
	import util.EffectShowCard;
	import util.MovieClipButton;
	
	import view.plugin.BaseScore;
	import view.plugin.GameChat;
	import view.plugin.GameResult;
	import view.plugin.PlayerInfoPanel;
	
	import view.layer.L;
	import view.plugin.BaseScore;
	import view.plugin.ChatPanel;
	import view.plugin.FloatText;
	import view.plugin.GameChat;
	import view.plugin.GameResult;
	import view.plugin.GlobalPanel;
	import view.plugin.MessageBox;
	import view.plugin.PlayerInfoPanel;
	import view.plugin.SelectPanel;
	import view.plugin.TimerCount;
	import view.plugin.UserImage;
	import util.ImageNumber;
	import util.DisplayUtil;
	import view.game.CardControl;
	
	public class DdzLordsView extends GameView
	{
		public var userViews:Array = [];				//三个玩家UI
		public var btnStart:SimpleButton;				//开始按钮
		public var btnBrightStart:SimpleButton;		//明牌开始按钮
		public var btnRestart:SimpleButton;			//再来一局按钮
		public var btnChangeTable:SimpleButton;		//换桌按钮
		public var btnOutCard:MovieClipButton;			//出牌按钮
		public var btnTrustee:MovieClipButton;			//托管按钮
		public var btnCannelTrustee:SimpleButton;		//取消托管按钮
		public var btnSort:SimpleButton;				//排序按钮
		public var btnTips:MovieClipButton;			//提示按钮
		public var btnPass:MovieClipButton;			//不出按钮
		public var btnCallLand:SimpleButton;			//叫地主按钮
		public var btnNotCallLand:SimpleButton;		//不叫按钮
		public var btnSnatchLand:SimpleButton;			//抢地主按钮
		public var btnNotSnatchLand:SimpleButton;		//不抢按钮
		public var btnDoubleScore:MovieClipButton;		//加倍按钮
		public var btnNotDoubleScore:MovieClipButton;	//不加倍按钮
		public var btnBrightCard:SimpleButton;			//明牌按钮
		public var btnNotBrightCard:SimpleButton;		//不明牌按钮
		public var btnCardType:Array;					//七个功能按钮
		
		public var mcTrustee:MovieClip;				//托管影片剪辑
		public var mcFeiji:MovieClip;					//飞机动画
		public var mcShunzi:MovieClip;					//顺子动画
		public var mcBomb:MovieClip;					//炸弹动画
		public var mcStart:MovieClip;					//开始动画
		public var mcTimer:MovieClip;					//计时动画
		public var main:MovieClip;						//swf资源
		
		public var backControl:CardControl;			//底牌控件
		public var baseScore:BaseScore;				//底分
		public var doubleScore:BaseScore;				//倍数
		public var gameResult:GameResult;				//成绩栏
		public var cardBitmapData:CardBitmapData;		//扑克牌
		
		private var effectShowCard:Array = [];			//逐张显示牌控制类
		private var timerCount:EffectCharAdd;			//计时控制类
		
		public function DdzLordsView(main:MovieClip)
		{
			this.main = main;
			
			var ready:Array = [];var info:Array = [];var tips:Array = [];
			var alarm:Array = [];
			ready.push(main.mcReady01, main.mcReady02, main.mcReady03);
			info.push(main.mcInfo01, main.mcInfo02, main.mcInfo03);
			tips.push(main.mcJiaofen01, main.mcJiaofen02, main.mcJiaofen03);
			alarm.push(null, main.alarm2, main.alarm3);
			var btns:Array = [{btn:main.btn1,type:GameLogic.CT_SINGLE_LINE},
				{btn:main.btn2,type:GameLogic.CT_DOUBLE_LINE},
				{btn:main.btn3,type:GameLogic.CT_MISSILE_CARD},
				{btn:main.btn4,type:GameLogic.CT_BOMB_CARD},
				{btn:main.btn5,type:GameLogic.CT_THREE_LINE},
				{btn:main.btn6,type:GameLogic.CT_DOUBLE},
				{btn:main.btn7,type:GameLogic.CT_THREE}];
			
			btnStart = main.btnStart;
			btnBrightStart = main.btnBrightStart;
			btnRestart = main.btnRestart;
			btnChangeTable = main.btnChangeTable;
			btnOutCard = new MovieClipButton(main.btnOutCard);
			btnTips = new MovieClipButton(main.btnTips);
			btnPass = new MovieClipButton(main.btnPass);
			btnTrustee = new MovieClipButton(main.btnTrustee);
			btnCannelTrustee = main.btnCannelTrustee;
			btnSort = main.btnSort;
			btnCallLand = main.btnCallLand;
			btnNotCallLand = main.btnNotCallLand;
			btnSnatchLand = main.btnSnatchLand;
			btnNotSnatchLand = main.btnNotSnatchLand;
			btnDoubleScore = new MovieClipButton(main.btnDoubleScore);
			btnNotDoubleScore = new MovieClipButton(main.btnNotDoubleScore);
			btnBrightCard = main.btnBrightCard;
			btnNotBrightCard = main.btnNotBrightCard;
			mcTrustee = main.mcTrustee;
			mcFeiji = main.feiji;
			mcShunzi = main.shunzi;
			mcBomb = main.bomb;
			mcStart = main.start;
			mcTimer = main.direction;
			var i:uint = 0;
			var mcb:MovieClipButton;
			for(i == 0; i < 7; i++)
			{
				mcb = new MovieClipButton(btns[i].btn);
				btnCardType.push({btn:mcb, type:btns[i].type});
			}
			
			mcStart.mouseEnabled = false;
			mcFeiji.mouseEnabled = false;
			mcShunzi.mouseEnabled = false;
			mcBomb.mouseEnabled = false;
			mcTrustee.gotoAndStop(1);
			mcTimer.gotoAndStop(1);
			baseScore = new BaseScore(main.baseScore, Resource.i.getBitmapData("number04"));
			doubleScore = new BaseScore(main.doubleScore, Resource.i.getBitmapData("number04"));
			var tmpBmp:Bitmap = Resource.i.getBitmap("cardbig");
			cardBitmapData = new CardBitmapData(tmpBmp);
			gameResult = new GameResult(main.mcResult);
			main.mcResult.parent.removeChild(main.mcResult);
			timerCount = new EffectCharAdd(null, 1000, 1, 30, 0, false);
			
			var orix:Number = 0;
			var oriy:Number = -40;
			var cardPoint:Array = [new Point(orix+416,oriy+566),new Point(orix+800,oriy+200),new Point(orix+20,oriy+200),new Point(main.width/2+3,oriy+100)];
			var outCardPoint:Array = [new Point(orix+416,oriy+445), new Point(orix+720, oriy+305), new Point(orix+112, oriy+305)];
			var chatButtlePos:Array = [new Point(orix+523,oriy+396),new Point(orix+523,oriy+232),new Point(orix+93,oriy+232)];
			var playerInfoPos:Array = [new Point(-180,-26),new Point(-180,-26),new Point(60,-26)];
			var userImagePos:Array = [new Point(748,394),new Point(748,208),new Point(34,208)];
			var bubbleClass:Array = ["ChatBubbleRightDown","ChatBubbleRightUp","ChatBubbleLeftUp"];
			var bubbleTxtPos:Array = [new Point(5, 8),new Point(12, 8),new Point(30, 8)];	
			var cardCountPos:Array = [null,new Point(762, 136),new Point(25, 136)];	
			var cardControlMode:Array = [{x:CardControl.enXCenter,y:CardControl.enYCenter},{x:CardControl.enXRight,y:CardControl.enYCenter},{x:CardControl.enXLeft,y:CardControl.enYCenter}];
			var outCardMode:Array = [{x:CardControl.enXCenter,y:CardControl.enYCenter},{x:CardControl.enXRight,y:CardControl.enYCenter},{x:CardControl.enXLeft,y:CardControl.enYCenter}];
			backControl = new CardControl(false);
			backControl.setBitmapData(cardBitmapData, 53, 70);
			backControl.setDirection(true);
			backControl.setBright(false);
			backControl.SetCardSpace(60, 0, 20);
			backControl.setBenchmarkPos(cardPoint[3], CardControl.enXCenter, CardControl.enYCenter);
			for(i = 0; i < Define.GAME_PLAYER; i++)
			{
				var userView:UserView = new UserView();
				userView.nickName = info[i].txtName;
				userView.ready = ready[i];
				userView.alarm = alarm[i];
				userView.tips = tips[i];
				userView.chatBubble = new GameChat(Resource.i.getMovieClip("common", bubbleClass[i]), bubbleTxtPos[i]);
				userView.userImage = new UserImage();
				userView.playerInfo = new PlayerInfoPanel(userView.userImage);
				userView.cardCount = i==0?null:new ImageNumber(Resource.i.getBitmapData("number01"));
				userView.cardControl = new CardControl(i==0);
				userView.outCardControl = new CardControl(false);
				
				with(userView.nickName)
				{
					mouseEnabled = false;
				}
				with(userView.chatBubble)
				{
					x = chatButtlePos[i].x; y = chatButtlePos[i].y;
				}
				with(userView.userImage)
				{
					x = userImagePos[i].x; y = userImagePos[i].y;
				}
				with(userView.playerInfo)
				{
					x = playerInfoPos[i].x; y = playerInfoPos[i].y;
				}
				if(userView.cardCount)
				{
					userView.cardCount.x = playerInfoPos[i].x; userView.cardCount.y = playerInfoPos[i].y;
					userView.cardCount.scaleX = 0.7;userView.cardCount.scaleX = 0.9;
					userView.cardCount.signVisible = false;
				}
				with(userView.cardControl)
				{
					setBright(i == 0);
					setDirection(true);
					SetCardSpace(i==0?24:12, 20, 16 );
					setBitmapData(cardBitmapData, i==0?75:42, i==0?102:58);
					setBenchmarkPos(cardPoint[i], outCardMode[i].x, outCardMode[i].y);
				}
				with(userView.outCardControl)
				{
					setBright(true);
					setDirection(true);
					SetCardSpace( 21, 20, 16 );
					setBitmapData(cardBitmapData, 75, 102);
					setBenchmarkPos(outCardPoint[i], CardControl.enXCenter, CardControl.enYCenter);
				}
				
				effectShowCard[i] = new EffectShowCard(150);
				main.addChild(userView.cardControl);
				main.addChild(userView.outCardControl);
				main.addChild(userView.chatBubble);
				main.addChild(userView.ready);
				main.addChild(info[i]);
				main.addChild(userView.userImage);
				info[i].mouseEnabled = false;
				userViews.push(userView);
			}
			
			main.addChild(btnCannelTrustee);
			main.addChild(backControl);
			main.addChild(userViews[1].alarm);
			main.addChild(userViews[2].alarm);
			main.addChild(baseScore);
			main.addChild(doubleScore);
		}
		
		private function initialize():void
		{
			DisplayUtil.showDisplayObject(btnOutCard, false);
			DisplayUtil.showDisplayObject(btnTips, false);
			DisplayUtil.showDisplayObject(btnPass, false);
			DisplayUtil.showDisplayObject(btnCannelTrustee, false);
			DisplayUtil.showDisplayObject(mcTrustee, false);
			DisplayUtil.showDisplayObject(mcFeiji, false);
			DisplayUtil.showDisplayObject(mcShunzi, false);
			DisplayUtil.showDisplayObject(mcBomb, false);
			DisplayUtil.showDisplayObject(mcStart, false);
			DisplayUtil.showDisplayObject(btnStart, false);
			DisplayUtil.showDisplayObject(btnBrightStart, false);
			DisplayUtil.showDisplayObject(btnRestart, false);
			DisplayUtil.showDisplayObject(btnChangeTable, false);
			DisplayUtil.showDisplayObject(btnCallLand, false);
			DisplayUtil.showDisplayObject(btnNotCallLand, false);
			DisplayUtil.showDisplayObject(btnSnatchLand, false);
			DisplayUtil.showDisplayObject(btnNotSnatchLand, false);
			DisplayUtil.showDisplayObject(btnDoubleScore, false);
			DisplayUtil.showDisplayObject(btnNotDoubleScore, false);
			DisplayUtil.showDisplayObject(btnBrightCard, false);
			DisplayUtil.showDisplayObject(btnNotBrightCard, false);
			DisplayUtil.showDisplayObject(backControl, false);
			DisplayUtil.showDisplayObject(btnNotBrightCard, false);
			DisplayUtil.showDisplayObject(btnNotBrightCard, false);
			DisplayUtil.showDisplayObject(baseScore, false);
			DisplayUtil.showDisplayObject(doubleScore, false);
			gameResult.show(false);
			
			for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
			{
				DisplayUtil.showDisplayObject(userViews[i].userImage, false);
				DisplayUtil.showDisplayObject(userViews[i].cardControl, false);
				DisplayUtil.showDisplayObject(userViews[i].outControl, false);
				DisplayUtil.showDisplayObject(userViews[i].chatBubble, false);
				DisplayUtil.showDisplayObject(userViews[i].ready, false);
				DisplayUtil.showDisplayObject(userViews[i].alarm, false);
				DisplayUtil.showDisplayObject(userViews[i].tips, false);
				DisplayUtil.showDisplayObject(userViews[i].cardCount, false);
			}
		}
	}
}